package tests;

import common.AutoTestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.io.IOException;

public class pageUser extends AutoTestUtil {
    /**
     * 用户中心的测试操作
     */
    public void successUserDetail() throws NoSuchMethodException, IOException, InterruptedException {

        driver.manage().window().maximize();
        //此时要进行跳转到博客列表页面，直接进行刷新即可
        driver.navigate().refresh();

        getScreen(this.getClass().getMethod("successUserDetail").getName());

        driver.findElement(By.cssSelector("#index_nav_nickname")).click();
        //再选择点击用户中心
        driver.findElement(By.cssSelector("#index_user_settings")).click();

        //最后直接查找元素即可
        try {
            String string = driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")).getText();
            if(string.equals("用户中心")){
                System.out.println("进入用户中心成功");
            }
        }catch (Exception e){
            System.out.println("successUserDeatil方法出现异常：" + e);
        }
        //最后找到电话栏直接进行修改(较为粗糙)
        WebElement element = driver.findElement(By.cssSelector("#setting_input_phoneNum"));

        //模拟鼠标滑动操作，找到元素位置
        Actions actions = new Actions(driver);
        actions.moveToElement(element).perform();

        element.sendKeys("191508762893");

        //点击修改
        driver.findElement(By.cssSelector("#setting_submit_phoneNum")).click();

        getScreen(this.getClass().getMethod("successUserDetail").getName());

        //TODO(头像的修改操作)
        element = driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div.row.align-items-center > div:nth-child(2) > a"));

        element.sendKeys("\"C:\\Users\\Administrator\\Pictures\\Saved Pictures\\微信图片_20240322153345.jpg\"");

        getScreen(this.getClass().getMethod("successUserDetail").getName());
    }
}
